<?php
// 接口API**********************
//username 用户名
// 接口API**********************
//建立数据库连接
$link = mysqli_connect('localhost','root','123456','twoStage');
//判断连接成功与否
if(!$link){
    die('连接失败'.mysqli_connect_error());
};
//设置编码
mysqli_set_charset($link,'utf8');

//sql语句，查找所有数据
 // 从文件中读取数据到PHP变量 
 $json_string =  json_decode(file_get_contents('../json/goods.json'),true);
 
 foreach($json_string as $key1 => $val1){
    foreach($val1 as $key2 => $val2){
        foreach($val2 as $key3 => $val3){
            foreach($val3 as $key4 => $val4){
                $url = $val4['url'];
                $mat = $val4['mat'];
                $price1 = $val4['price1'];
                $price2 = $val4['price2'];
                $shop = $val4['shop'];
                $add = "insert into goods set bigNav='$key1',midNav='$key2',smaNav='$key3',goodsname='$key4',mat='$mat',url='$url',price1='$price1',price2='$price2',shop='$shop'";
                //执行sql语句
                if ($link->query($add) === TRUE) {
                    echo "新记录插入成功";
                } else {
                    echo "Error: " . $add . "<br>" . $link->error;
                };
            };
        };
    };
  };
//关闭数据库连接
mysqli_close($link);
?>